package com.woniuxy.controller;

import cn.hutool.core.util.StrUtil;
import com.woniuxy.entity.dto.OrderParamDTO;
import com.woniuxy.service.OrderService;
import com.woniuxy.util.ResponseData;
import com.woniuxy.util.ResponseEnum;
import lombok.AllArgsConstructor;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * @author ：CuiYC
 * @description：
 * @date ：Created in 2025/3/14 11:17
 * @modified By：
 */
@RestController
@RequestMapping("/order")
@AllArgsConstructor
public class OrderController {

    private OrderService orderService;
    @PostMapping("/addOrder")
    public ResponseData<?> addOrder(@RequestBody OrderParamDTO orderParamDTO){
        try {
            //校验参数
            /**
             * 空参校验
             */
            if(orderParamDTO.getAddrId() == null || CollectionUtils.isEmpty(orderParamDTO.getCartIds())){
                return ResponseData.fail(ResponseEnum.PARAM_ERROR);
            }
            return orderService.addOrder(orderParamDTO);
        } catch (ParseException | InterruptedException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}
